package com.dr.controller.index;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dr.entity.Comment;
import com.dr.entity.Orderdetail;
import com.dr.entity.User;
import com.dr.service.CommentWebService;
import com.dr.service.OrderinfoService;

@Controller
@RequestMapping("/index/")
public class CommentWebController {

	@Autowired
	private CommentWebService commentWebService;
   @Autowired
   private OrderinfoService orderinfoService;
  //跳转到评价页面：显示这个订单未评价的产品
	@RequestMapping("/toComment.do")
	public String findComment(String orderId,Model model,HttpSession session) {
		List<Orderdetail> list=orderinfoService.findNoCommentByOrderId(orderId);
		model.addAttribute("list",list);
		session.setAttribute("MyCommentNum",list.size());
	     return "myprod.jsp";
	}
	//提交评价
	@RequestMapping("/addComment.do")
	public String addComment(Comment comment,String orderId,Model model,HttpSession session,Integer detailId) {
		User user=(User) session.getAttribute("loginUser");
		comment.setUser_id(user.getId());
		comment.setIsReply(0);
		commentWebService.addComment(comment);
		//修改明细表里的isComment=1
		orderinfoService.updateIscommentById(detailId);
		int  MyCommentNum=(Integer) session.getAttribute("MyCommentNum");
		if (MyCommentNum == 1) {
			orderinfoService.editOrderInfoWc(orderId);
		}
	     return "toComment.do";
	}
}